﻿using log4net;
using MvcCms.Service.Cache;
using Microsoft.Practices.ServiceLocation;
namespace MvcCms.Service.Logging
{
    public static class AppLogging
    {
        private const string LoggerName = "MvcCms";
        private static ILog _logger;
        private static readonly object Obj = new object();

        private static void Init()
        {
        }

        public static ILog GetLogger(bool dontUsePortalName)
        {
            lock (Obj)
            {
                if (_logger == null)
                {
                    log4net.Config.XmlConfigurator.Configure();

                    _logger = log4net.LogManager.GetLogger(LoggerName);
                }

                return _logger;
            }
        }
        public static ILog GetLogger()
        {
            var cacheService = ServiceLocator.Current.GetInstance<ICacheService>(); 
            
            var currentPortal = cacheService.GetCurrentPortal();
            lock (Obj)
            {
                if (_logger == null)
                {
                    log4net.Config.XmlConfigurator.Configure();

                    _logger = log4net.LogManager.GetLogger(currentPortal.Name);
                }

                return _logger;
            }
        }
    }
}
